package main

import (
	"encoding/json"
	"fmt"
	"os"
)

func GenerateJson() {
	type Stu struct {
		Name     string
		Age      int
		Sex      string
		Favorite []string
	}

	stu := Stu{
		Name:     "Jesse",
		Age:      18,
		Sex:      "male",
		Favorite: []string{"read", "hiking", "run", "movie"},
	}

	data, err := json.Marshal(stu)
	if err != nil {
		fmt.Printf("err: %v\n", err)
	}
	os.Stdout.Write(data)

}

func ParsingJson() {
	var jsonContent = []byte(`[
		{"Name":"Jesse","Age":21},
		{"Name":"maggie","Age":17}
	]`)

	type Stu struct {
		Name string
		Age  int
	}

	var stu []Stu

	err := json.Unmarshal(jsonContent, &stu)
	if err != nil {
		fmt.Println("error:", err)
	}

	fmt.Printf("%+v", stu)
}

func main() {
	//GenerateJson()
	ParsingJson()
}
